import mongoose from 'mongoose';

export default defineNitroPlugin(async () => {
	console.log('Mongoose Plugin Loading...');

	const defaultMongoDBUri = 'mongodb://localhost:27017/ly-resource-navigation';

	// 连接 MongoDB 数据库
	try {
		await mongoose.connect(process.env.MONGODB_URI || defaultMongoDBUri);
		console.log('Connected to MongoDB!');
	} catch (error: any) {
		const err: Error = error;
		console.error('Error connecting to MongoDB:', err.message);
	}
});
